#include <vector>
#include <set>
#include <iostream>
#include <unordered_map>
using namespace std;

vector<int> myfindDuplicates(vector<int>& nums) {
    int n = 100000;
    for(int num : nums){
        if(num <= n){
            nums[num-1] += n;
        }else if(num <= 2*n){
            nums[num-n-1] += n;
        }else{
            nums[num-2*n-1] += n;
        }
    }
    for(int i = nums.size()-1; i >= 0; i--){
        if(nums[i] < 2*n){
            nums.erase(nums.begin()+i);
        }else{
            nums[i] = i + 1;
        }
    }
    return nums;
}

vector<int> findDuplicates(vector<int>& nums) {
    int n = nums.size();
    vector<int> ans;
    for (int i = 0; i < n; ++i) {
        int x = abs(nums[i]);
        if (nums[x - 1] > 0) {
            nums[x - 1] = -nums[x - 1];
        }
        else {
            ans.push_back(x);
        }
    }
    return ans;
}

int main(){
    vector<int> nums = { 4,3,2,7,8,2,3,1 };
    vector<int> out = findDuplicates(nums); 
    cout << out[0] << "," << out[1] << endl;
    return 0;
}